// cats.controller.ts
import {
  Controller,
  Get,
  Post,
  Body,
  Req,
  Request,
  Delete,
  Patch,
  UseGuards,
  Param
} from '@nestjs/common';
import { UserService } from '../service/user.service';
import { ToolsService } from 'common/lib/utils/tools.service';
import { AuthGuard } from '@nestjs/passport';

@Controller('user')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Get('find-all')
  @UseGuards(AuthGuard('jwt')) //jwt策略，身份鉴权
  async findAll(@Req() request: any): Promise<any> {
    return this.userService.findAll();
    // return ToolsService.fail('测试错误返回格式');
    // return "user list Get"
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.userService.findOne(id);
  }

  @Post('add')
  async create(@Body() body: any, @Req() request: any): Promise<any> {
    return this.userService.create(body);
  }

  @Post('update')
  async update(@Body() body: any, @Req() request: any): Promise<any> {
    return this.userService.update(body);
  }

  @Post('remove')
  async remove(@Body() body: any, @Req() request: any): Promise<any> {
    return this.userService.remove(body.id);
  }
}
